import { shapeType } from "src/types/drawBoard";
import Base from "./Base";
import utils from "src/utils";

export interface TriangleProps {
  x: number;
  y: number;
  width: number;
  height: number;
  borderWidth?: number;
  borderColor?: string;
  bgcolor?: string;
}

export default class extends Base {
  constructor(option: TriangleProps) {
    super(shapeType.triangle)
    utils.object.Assign(option, this.props)
  }
  draw(ctx: CanvasRenderingContext2D, osCtx: OffscreenCanvasRenderingContext2D): void {
    const { x, y, width, height } = this.props

    ctx.save()

    this.transform(ctx)

    ctx.beginPath()
    this.initOptions(ctx, 1)
    ctx.moveTo(x, y)
    ctx.lineTo(x + width, y + height)
    ctx.lineTo(x, y + height)
    ctx.closePath()
    ctx.stroke()

    ctx.restore()

    // 镜像画布
    this.drawMirror(osCtx)
  }
}